package com.ruoyi.web.controller.wisdom;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.wisdom.domain.FzServiceCulture;
import com.ruoyi.wisdom.service.IFzServiceCultureService;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 小区活动Controller
 * 
 * @author ruoyi
 * @date 2020-03-05
 */
@Controller
@RequestMapping("/wisdom/culture")
public class FzServiceCultureController extends BaseController
{
    private String prefix = "wisdom/culture";

    @Autowired
    private IFzServiceCultureService fzServiceCultureService;

    @RequiresPermissions("wisdom:culture:view")
    @GetMapping()
    public String culture()
    {
        return prefix + "/culture";
    }

    /**
     * 查询小区活动列表
     */
    @RequiresPermissions("wisdom:culture:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpSession session, FzServiceCulture fzServiceCulture)
    {
        startPage();
        fzServiceCulture.setcId(GetSessionValueUtil.getCommunity());
        List<FzServiceCulture> list = fzServiceCultureService.selectFzServiceCultureList(fzServiceCulture);
        return getDataTable(list);
    }

    /**
     * 导出小区活动列表
     */
    @RequiresPermissions("wisdom:culture:export")
    @Log(title = "小区活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzServiceCulture fzServiceCulture)
    {
        List<FzServiceCulture> list = fzServiceCultureService.selectFzServiceCultureList(fzServiceCulture);
        ExcelUtil<FzServiceCulture> util = new ExcelUtil<FzServiceCulture>(FzServiceCulture.class);
        return util.exportExcel(list, "culture");
    }

    /**
     * 新增小区活动
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存小区活动
     */
    @RequiresPermissions("wisdom:culture:add")
    @Log(title = "小区活动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzServiceCulture fzServiceCulture)
    { System.out.println(fzServiceCulture);
        fzServiceCulture.setCultureId(HeadNum.CULTURE_HEAD+DateUtils.getTimeMillis());
        System.out.println(fzServiceCulture);
        fzServiceCulture.setcId(GetSessionValueUtil.getCommunity());
        fzServiceCulture.setCreateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzServiceCultureService.insertFzServiceCulture(fzServiceCulture));
    }

    /**
     * 修改小区活动
     */
    @GetMapping("/edit/{cultureId}")
    public String edit(@PathVariable("cultureId")String cultureId, ModelMap mmap)
    {

        FzServiceCulture fzServiceCulture = fzServiceCultureService.selectFzServiceCultureById(cultureId);
        mmap.put("fzServiceCulture", fzServiceCulture);
        return prefix + "/edit";
    }

    /**
     * 修改保存小区活动
     */
    @RequiresPermissions("wisdom:culture:edit")
    @Log(title = "小区活动", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzServiceCulture fzServiceCulture)
    {
        fzServiceCulture.setUpdateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzServiceCultureService.updateFzServiceCulture(fzServiceCulture));
    }

    /**
     * 删除小区活动
     */
    @RequiresPermissions("wisdom:culture:remove")
    @Log(title = "小区活动", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzServiceCultureService.deleteFzServiceCultureByIds(ids));
    }
}
